package com;

import com.pojo.Employee;
import com.Utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeByIdTest(){
        SqlSession sqlSession= MyBatisUtils.getSqlSession();
        Employee employee =sqlSession.selectOne("com.mapper.EmployeeMapper.selectByPrimaryKey",3L);
        System.out.println(employee.toString());
    }
    @Test
    public void addEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();

        employee.setId(4);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");

        int addInt = sqlSession.insert("com.mapper.EmployeeMapper.insert",employee);
        sqlSession.commit();
        sqlSession.close();
        System.out.print(addInt);
    }
        @Test
                public void updateEmployeeTest(){
            SqlSession sqlSession = MyBatisUtils.getSqlSession();
            Employee employee = new Employee();
            employee.setId(2);
            employee.setName("赵六");
            employee.setAge(16);
            employee.setPosition("临时工");
            int u =sqlSession.update("com.mapper.EmployeeMapper.updateByPrimaryKey", employee);
            sqlSession.commit();
            sqlSession.close();
            System.out.print(u);
        }

        @Test

    public void deleteEmployeeById(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        int d =sqlSession.delete("com.mapper.EmployeeMapper.deleteByPrimaryKey",1L);
        sqlSession.commit();
        sqlSession.close();
            System.out.println(d);
        }

}
